﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Calculations
{
	public class CalculationPresenter
	{
		ICalculationModel _model;
		ICalculationView _view;

		public CalculationPresenter(ICalculationView view, ICalculationModel model)
		{
			_view = view;
			_model = model;
			view.Load += new EventHandler(view_Load);
			view.ValueUpdated += new EventHandler(view_ValueUpdated);
		}

		void view_ValueUpdated(object sender, EventArgs e)
		{
			_model.WoodRate = _view.WoodRate;
			_model.IronRate = _view.IronRate;
			_model.ClayRate = _view.ClayRate;
			_model.CropRate = _view.CropRate;

			_model.StartingValues = new SnapShot(_view.Wood, _view.Clay, _view.Crop, _view.Iron);

			_view.Timeline = _model.Timeline(_view.TimelineLength);
		}

		void view_Load(object sender, EventArgs e)
		{
			_view.WoodRate = _model.WoodRate;
			_view.IronRate = _model.IronRate;
			_view.ClayRate = _model.ClayRate;
			_view.CropRate = _model.CropRate;

			SnapShot values = _model.StartingValues;

			_view.Wood = values.Wood;
			_view.Iron = values.Iron;
			_view.Clay = values.Clay;
			_view.Crop = values.Crop;

			_view.TimelineLength = 10;

			_view.Timeline = _model.Timeline(10);
		}
	}
}
